package com.yellowpage.client.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.client.data.UserInfo;
import com.yellowpage.client.dao.UserInfoDao;

public class UserInfoServiceImpl extends BaseServiceImpl implements UserInfoService {
	  private UserInfoDao userInfoDao;
	
	  public void setUserInfoDao(UserInfoDao userInfoDao) {
		  this.userInfoDao = userInfoDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public UserInfo getUserInfo(Long id){
	      return userInfoDao.get(id);
	  }
	  
    public List<UserInfo> getAllUserInfo(){
        return userInfoDao.getAll();
    }
    
    public List<Map> queryUserInfoByPage(Map queryMap, PageRender pageRender) {		
    	
    	return userInfoDao.queryUserInfoByPage(queryMap, pageRender);
    	
    	/*
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT A.MUID , A.CUST_ID , A.USERNAME , A.ESN , A.PHONE_CATEG , A.PHONE , A.IMSI , A.CLASSID , A.LEVEL_ID , A.TELPHONE , A.EMAIL , A.SEX , A.BIRTHDAY , A.PNO , A.PROVINCE , A.CITY , A.DISTRICT , A.ADRESS , A.ADD_CHANNEL , A.ADD_TIME , A.TEL_INTEGRAL , A.SL_INTEGRAL , A.BALANCE , A.LAST_LOGIN , A.LAST_IP , A.SEQNO , A.MAC_KEY , A.CERTIFICATETYPE , A.CERTIFICATECODE , A.FIELD1 , A.FIELD2 , A.FIELD3 , A.NAME , A.ID , A.TYPE , A.VERSION , A.PASSWORD , A.STATUS    FROM USER_INFO A WHERE 1=1 ")
    			.addCondition(" and MUID = :muid ")
			    			.addCondition(" and CUST_ID = :custId ")
			    			.addCondition(" and USERNAME = :username ")
			    			.addCondition(" and ESN = :esn ")
			    			.addCondition(" and PHONE_CATEG = :phoneCateg ")
			    			.addCondition(" and PHONE = :phone ")
			    			.addCondition(" and IMSI = :imsi ")
			    			.addCondition(" and CLASSID = :classid ")
			    			.addCondition(" and LEVEL_ID = :levelId ")
			    			.addCondition(" and TELPHONE = :telphone ")
			    			.addCondition(" and EMAIL = :email ")
			    			.addCondition(" and SEX = :sex ")
			    		    .addCondition(" and date_format(BIRTHDAY,'%Y-%m-%d') =  :birthday  ")
			    			.addCondition(" and PNO = :pno ")
			    			.addCondition(" and PROVINCE = :province ")
			    			.addCondition(" and CITY = :city ")
			    			.addCondition(" and DISTRICT = :district ")
			    			.addCondition(" and ADRESS = :adress ")
			    			.addCondition(" and ADD_CHANNEL = :addChannel ")
			    			.addCondition(" and ADD_TIME = :addTime ")
			    			.addCondition(" and TEL_INTEGRAL = :telIntegral ")
			    			.addCondition(" and SL_INTEGRAL = :slIntegral ")
			    			.addCondition(" and BALANCE = :balance ")
			    			//.addCondition(" and date_format(last_login,'%Y-%m-%d') = :lastLogin ")
			    			.addCondition(" and date_format(LAST_LOGIN,'%Y-%m-%d') >= :lastLogin ")
			    			.addCondition(" and date_format(LAST_LOGIN,'%Y-%m-%d') <= :lastLoginend ")
			    			.addCondition(" and LAST_IP = :lastIp ")
			    			.addCondition(" and SEQNO = :seqno ")
			    			.addCondition(" and MAC_KEY = :macKey ")
			    			.addCondition(" and CERTIFICATETYPE = :certificatetype ")
			    			.addCondition(" and CERTIFICATECODE = :certificatecode ")
			    			.addCondition(" and FIELD1 = :field1 ")
			    			.addCondition(" and FIELD2 = :field2 ")
			    			.addCondition(" and FIELD3 = :field3 ")
			    			.addCondition(" and NAME = :name ")
			    			.addCondition(" and ID = :id ")
			    			.addCondition(" and TYPE = :type ")
			    			.addCondition(" and VERSION = :version ")
			    			.addCondition(" and PASSWORD = :password ")
			    			.addCondition(" and STATUS = :status ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;*/
	}
    
 public List<Map> userInfoServiceexcel(Map queryMap) {		
	 
	 return userInfoDao.queryUserInfo(queryMap);

/*
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT A.MUID , A.CUST_ID , A.USERNAME , A.ESN , A.PHONE_CATEG , A.PHONE , A.IMSI , A.CLASSID , A.LEVEL_ID , A.TELPHONE , A.EMAIL , A.SEX , A.BIRTHDAY , A.PNO , A.PROVINCE , A.CITY , A.DISTRICT , A.ADRESS , A.ADD_CHANNEL , A.ADD_TIME , A.TEL_INTEGRAL , A.SL_INTEGRAL , A.BALANCE , A.LAST_LOGIN , A.LAST_IP , A.SEQNO , A.MAC_KEY , A.CERTIFICATETYPE , A.CERTIFICATECODE , A.FIELD1 , A.FIELD2 , A.FIELD3 , A.NAME , A.ID , A.TYPE , A.VERSION , A.PASSWORD , A.STATUS    FROM USER_INFO A WHERE 1=1 ")
				    			.addCondition(" and MUID = :muid ")
							    			.addCondition(" and CUST_ID = :custId ")
							    			.addCondition(" and USERNAME = :username ")
							    			.addCondition(" and ESN = :esn ")
							    			.addCondition(" and PHONE_CATEG = :phoneCateg ")
							    			.addCondition(" and PHONE = :phone ")
							    			.addCondition(" and IMSI = :imsi ")
							    			.addCondition(" and CLASSID = :classid ")
							    			.addCondition(" and LEVEL_ID = :levelId ")
							    			.addCondition(" and TELPHONE = :telphone ")
							    			.addCondition(" and EMAIL = :email ")
							    			.addCondition(" and SEX = :sex ")
							    		    .addCondition(" and date_format(BIRTHDAY,'%Y-%m-%d') =  :birthday  ")
		    				    			.addCondition(" and PNO = :pno ")
							    			.addCondition(" and PROVINCE = :province ")
							    			.addCondition(" and CITY = :city ")
							    			.addCondition(" and DISTRICT = :district ")
							    			.addCondition(" and ADRESS = :adress ")
							    			.addCondition(" and ADD_CHANNEL = :addChannel ")
							    			.addCondition(" and ADD_TIME = :addTime ")
							    			.addCondition(" and TEL_INTEGRAL = :telIntegral ")
							    			.addCondition(" and SL_INTEGRAL = :slIntegral ")
							    			.addCondition(" and BALANCE = :balance ")
							    			//.addCondition(" and date_format(last_login,'%Y-%m-%d') = :lastLogin ")
							    			.addCondition(" and date_format(LAST_LOGIN,'%Y-%m-%d') >= :lastLogin ")
							    			.addCondition(" and date_format(LAST_LOGIN,'%Y-%m-%d') <= :lastLoginend ")
							    			.addCondition(" and LAST_IP = :lastIp ")
							    			.addCondition(" and SEQNO = :seqno ")
							    			.addCondition(" and MAC_KEY = :macKey ")
							    			.addCondition(" and CERTIFICATETYPE = :certificatetype ")
							    			.addCondition(" and CERTIFICATECODE = :certificatecode ")
							    			.addCondition(" and FIELD1 = :field1 ")
							    			.addCondition(" and FIELD2 = :field2 ")
							    			.addCondition(" and FIELD3 = :field3 ")
							    			.addCondition(" and NAME = :name ")
							    			.addCondition(" and ID = :id ")
							    			.addCondition(" and TYPE = :type ")
							    			.addCondition(" and VERSION = :version ")
							    			.addCondition(" and PASSWORD = :password ")
							    			.addCondition(" and STATUS = :status ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.query(
				baseDao.getConnection(), queryMap);

		return resultList;*/
	}
    
    public void saveUserInfo(UserInfo userInfo){
        userInfoDao.save(userInfo);
    }
    
	  public void updateUserInfo(UserInfo userInfo){
	      userInfoDao.update(userInfo);
	  }
	  
	  public void delete(List deleteList){
	      userInfoDao.remove(deleteList);
	  }
	  
	  
	 
	
}	